home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / arosdv19.lha / AROS / config / machine.c < prev    next >
C/C++ Source or Header  |  1996-10-23  |  3KB  |  125 lines

  1. #include <stdio.h>
  2. #include <stddef.h>
  3. #include <exec/types.h>
  4.  
  5. #ifndef _AMIGA
  6. #   if defined(AMIGA) || defined(__AMIGA__)
  7. #    define _AMIGA
  8. #   endif
  9. #endif
  10.  
  11. struct __aros_longalign
  12. {
  13.     char dummy;
  14.     LONG offset;
  15. };
  16.  
  17. struct __aros_wordalign
  18. {
  19.     char dummy;
  20.     WORD offset;
  21. };
  22.  
  23. struct __aros_ptralign
  24. {
  25.     char dummy;
  26.     APTR offset;
  27. };
  28.  
  29. struct __aros_iptralign
  30. {
  31.     char dummy;
  32.     IPTR offset;
  33. };
  34.  
  35. struct __aros_doublealign
  36. {
  37.     char dummy;
  38.     double offset;
  39. };
  40.  
  41. long sub (void)
  42. {
  43.     char b; /* This MUST NOT BE static ! */
  44.     long adr = (long)&b;
  45.  
  46.     return adr;
  47. }
  48.  
  49. int main (void)
  50. {
  51.     char a;
  52.     long adr1, adr2;
  53.     long val;
  54.     char * first_byte;
  55.     int wordalign;
  56.     int longalign;
  57.     int ptralign;
  58.     int iptralign;
  59.     int doublealign;
  60.     int worstalign;
  61.  
  62.     /* Calculate the addresses of two *local* variables */
  63.     adr1 = (long)&a;
  64.     adr2 = sub();
  65.  
  66.     /* If this is a normal stack, memory looks like this:
  67.  
  68.         adr2 (b)
  69.         ...
  70.         adr1 (a)
  71.  
  72.        because adr1 (a) is pushed on the stack and the stackpointer
  73.        is decreased (*--sp=a). Otherwise it looks like:
  74.  
  75.         adr1 (a)
  76.         ...
  77.         adr2 (b)
  78.     */
  79.  
  80.     /*
  81.     The difference between big and little endian is this:
  82.  
  83.     Big endian stores the value 0x11223344 as { 0x11, 0x22, 0x33, 0x44 }
  84.     (ie. the first byte in memory is the most significant byte of the
  85.     variable).
  86.  
  87.     Little endian stores the value 0x11223344 as { 0x44, 0x33, 0x22, 0x11 }
  88.     (ie. the first byte in memory is the least significant byte of the
  89.     variable).
  90.     */
  91.  
  92.     val = 0x11223344;
  93.  
  94.     first_byte = (char *)&val; /* Check if the first byte is 0x11 */
  95.  
  96.     wordalign    = offsetof(struct __aros_wordalign,    offset);
  97.     longalign    = offsetof(struct __aros_longalign,    offset);
  98.     ptralign    = offsetof(struct __aros_ptralign,     offset);
  99.     iptralign    = offsetof(struct __aros_iptralign,    offset);
  100.     doublealign = offsetof(struct __aros_doublealign,  offset);
  101.  
  102.     worstalign = wordalign;
  103.     if (worstalign < longalign)   worstalign = longalign;
  104.     if (worstalign < ptralign)    worstalign = ptralign;
  105.     if (worstalign < iptralign)   worstalign = iptralign;
  106.     if (worstalign < doublealign) worstalign = doublealign;
  107.  
  108. #ifdef _AMIGA
  109.     if (worstalign < 8) worstalign = 8;
  110. #endif
  111.  
  112.     printf ("#define AROS_STACK_GROWS_DOWNWARDS %d /* Stack direction */\n", (adr2 < adr1));
  113.     printf ("#define AROS_BIG_ENDIAN            %d /* Big or little endian */\n", (*first_byte == 0x11));
  114.     printf ("#define AROS_SIZEOFULONG           %d /* Size of an ULONG */\n", sizeof (ULONG));
  115.     printf ("#define AROS_WORDALIGN             %d /* Alignment for WORD */\n",   wordalign);
  116.     printf ("#define AROS_LONGALIGN             %d /* Alignment for LONG */\n",   longalign);
  117.     printf ("#define AROS_PTRALIGN              %d /* Alignment for PTR */\n",    ptralign);
  118.     printf ("#define AROS_IPTRALIGN             %d /* Alignment for IPTR */\n",   iptralign);
  119.     printf ("#define AROS_DOUBLEALIGN           %d /* Alignment for double */\n", doublealign);
  120.     printf ("#define AROS_WORSTALIGN            %d /* Worst case alignment */\n", worstalign);
  121.  
  122.     return 0;
  123. }
  124.  
  125.